/*
 * Author: junz
 */

import {defHttp} from '/@/utils/http/axios';
import {Course, CourseListGetResultModel} from '/@/model/resource/courseModel';
import {ErrorMessageMode} from "/#/axios";

enum Api {
    GET_COURSE_ENTITY_PAGE_LIST = '/continuingEducationCourse/course/page',
    GET_COURSE_ENTITY_BY_ID = '/continuingEducationCourse/course/',
    COURSE_ENTITY_UPDATE = '/continuingEducationCourse/course/updateById',
    COURSE_ENTITY_SAVE = '/continuingEducationCourse/course/save',
    COURSE_ENTITY_DEL = '/continuingEducationCourse/course/logicalRemoveById/',
}

/**
 * @description: Get sample list value
 */

export const getCoursePageApi = (params: {}) =>
    defHttp.get < CourseListGetResultModel > (
        {url: Api.GET_COURSE_ENTITY_PAGE_LIST, params},
            {errorMessageMode: 'message'}
    );

export const getCourseByIdApi = (id) =>
    defHttp.get < Course > (
        {url: Api.GET_COURSE_ENTITY_BY_ID + id},
            {errorMessageMode: 'message'}
    );

export function courseUpdateApi(params: Course, mode: ErrorMessageMode = 'modal') {
    return defHttp.put < Course > (
        {
            url: Api.COURSE_ENTITY_UPDATE,
            params,
        },
            {
                errorMessageMode: mode,
            }
    );
}
export const courseDelByIdApi = (id) =>
    defHttp.delete < Course > (
        {url: Api.COURSE_ENTITY_DEL + id},
            {errorMessageMode: 'message'}
    );


export function courseSaveApi(params: Course, mode: ErrorMessageMode = 'modal') {
    return defHttp.post < Course > (
        {
            url: Api.COURSE_ENTITY_SAVE,
            params,
        },
            {
                errorMessageMode: mode,
            }
    );
}

